$(function(){
	$(".customer_head").on("click","span",function(){
		$(this).addClass("current_span").siblings().removeClass("current_span");
		$(".customer_content").hide().eq($(this).index()).show();
	});
	
	 // 手机号码验证    
    jQuery.validator.addMethod("isMobile", function(value, element) {    
      var length = value.length;    
      return this.optional(element) || (length == 11 && /^(((13[0-9]{1})|(14[0-9]{1})|(15[0-35-9]{1})|(17[0-9]{1})|(18[0-9]{1}))+\d{8})$/.test(value));    
    }, "请正确填写手机号码。");
		
	$("#form").validate({
		 rules:{
		 	userCode4Show : {  
                required:true
            },
            userName : {  
                required:true
            },
            phone : {  
                required:true,
                isMobile:true
            },     
            password : {  
                required:true,  
                minlength:6,  
                maxlength:16  
            }
        },
        messages:{
       		userName:{
        		required:"请输入姓名"
        	},
        	userCode4Show:{
        		required:"请输入用户名"
        	},
            phone : {  
                required:"请输入手机号",
                isMobile:"请输入有效的手机号"
            },
        	password:{
        		required:"请输入密码",
        		minlength:jQuery.format("密码不能小于{6}个字符"),
        		maxlength:jQuery.format("密码不能大于{16}个字符")
        	}
        },
		debug:true,
		onkeyup:false,
		focusCleanup:false,
		success:"valid",
		invalidHandler: function(form, validator) {return false;},
		submitHandler: function(form) {
			var json = $('#form').serialize();
//			var jsonSrt =  formToJson(json);
//			var jsonObj = JSON.parse(jsonSrt);
//			jsonStr= JSON.stringify(jsonObj);
			//var jsonStr= JSON.stringify(dataJson);
			//alert(jsonStr)  
	        $.ajax({  
	          type : 'post',  
	          //contentType : 'application/json;charset=utf-8',
	          url : 'save',
	          data : json,
	          success : function(data) {
	        	  var rsult = jQuery.parseJSON(data);
	        	  if (rsult.success) {
	        		  alert("保存成功！");
	        		  window.parent.location.reload();
	        	  } else 
	        		  alert("保存失败!" + rsult.message);
	          },  
	          error : function(data) {  
	              alert("保存失败！")  
	          }  
	        });
	        return false;
		}
	});
})

//将从form中通过$('#form').serialize()获取的值转成json  
function formToJson(data) { 
	
   data=data.replace(/&/g,"\",\"");  
   data=data.replace(/=/g,"\":\"");  
   data="{\""+data+"\"}";
//  data=data.replace(/&/g,",\"");  
//  data=data.replace(/=/g,"\":");  
//  data="{\""+data+"}";
   return data;  
} 

function DeptId(name, hidden) {	
    jElass.exec({
        input: name,
        hidden: hidden,
        url: '../dept/search',
	    error : '很抱歉 暂时没有匹配的部门',width: 100
    });
}

//弹层函数
function order_edit(title,url,w,h){
		layer.close();
		var index = layer.open({
			type: 5,
			title: title,
			content: url,
		});
		layer.full(index);
}
function update_password(title,url,w,h){
	layer_show(title,url,w,h);	
}